/**
 * 
 */
package com.blueocean_health.care.management.controller;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.blueocean_health.care.management.common.base.em.TimeType;
import com.blueocean_health.care.management.common.base.time.TimeUtils;
import com.blueocean_health.care.management.common.excel.ExcelUtil;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.transfer.client.OrderClient;
import com.blueocean_health.care.management.transfer.dto.OrderSelectInfoEntity;
import com.blueocean_health.care.management.transfer.dto.SelectOrderVo;

/**
* @Title: OrderSelectController.java
* @Package com.blueocean_health.care.management.controller
* @author lcx
* @date 2018年7月18日
* @version V1.0
*/
@RestController
@RequestMapping(value = {"/order"}, produces = MediaType.APPLICATION_JSON_VALUE)
public class OrderSelectController {
	@Autowired
	private OrderClient  orderClient;
	@RequestMapping(value = "list")
	//查询订单列表
	public SysResult selectOrderList(@RequestBody(required = false) SelectOrderVo order){
		SysResult selectOrderList = orderClient.selectOrderList(order);
		return selectOrderList;
		
	}
	@RequestMapping(value = "relationList")
	//查询关联订单列表
	public SysResult relationList(@RequestBody(required = false) SelectOrderVo order){
		return orderClient.relationList(order);
		
	}
	@RequestMapping(value = "listExcel")
	//查询订单列表
		public void selectOrderListExcel(SelectOrderVo order,HttpServletResponse response){
			try {
				List<OrderSelectInfoEntity> list = orderClient.listforExcel(order);
				String finalFileName = URLEncoder.encode("订单列表"+TimeUtils.getTime(TimeType.yyyyMMddHHmmssSSS)+".xls", "UTF8");
				//response.addHeader("Content-Disposition", "attachment;filename=" + finalFileName);
				response.setContentType("application/force-download");
				response.addHeader("Content-Disposition", "attachment;filename=" + finalFileName);
				OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
				ExcelUtil.getInstance().exportObj2Excel(toClient, list, OrderSelectInfoEntity.class);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		}
	//查询订单详情
	@RequestMapping(value = "query")
	public SysResult selectOrderInfo(@RequestBody SelectOrderVo order){
		
		return 	orderClient.selectOrderInfo(order);
		
	}
}
